#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time         : 17-12-12 下午8:15
# @Author       : xiaohan
# @File         : yunpian.py
# @desc         :
import json

import requests

from cadmin.settings import sms_text, sms_api_key


class YunPian(object):

    def __init__(self):
        self.api_key = sms_api_key
        self.single_send_url = 'https://sms.yunpian.com/v2/sms/single_send.json'

    def send_sms(self, code, phone):
        params = {'apikey': self.api_key, 'mobile': phone, 'text': sms_text.format(code=code)}
        response = requests.post(url=self.single_send_url, data=params)
        ret = json.loads(response.text)
        return json.loads(response.text)


if __name__ == '__main__':
    yp = YunPian()
    yp.send_sms('1234', '18600884747')
